<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:fn="http://java.sun.com/jsp/jstl/functions"
    template="/WEB-INF/templates/common.xhtml">

                <ui:define name="pageTitle">Listagem de Pessoas</ui:define>

                <ui:define name="pageHeader">Listagem de Pessoas</ui:define>

                
                <ui:define name="body">
                        <h:messages errorStyle="color: red" infoStyle="color: green" layout="table" />
            <h:form id="personListForm" styleClass="table_list">
                    <h:commandButton action="/person/edit" value="Cadastrar Pessoa" />
                    <h:dataTable value="#{personController.personList}" var="item" border="0" cellpadding="2" cellspacing="0" rowClasses="odd_row,even_row" rules="all" style="border:solid 1px">
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="Id"/>
                                    </f:facet>
                                    <h:outputText value=" #{item.personId}"/>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="Nome"/>
                                    </f:facet>
                                    <h:outputText value=" #{item.name}"/>
                                </h:column>                             
                                <h:column>
                                        <f:facet name="header">
                                        <h:outputText value="Nascimento"/>
                                    </f:facet>
                                        <h:outputText value="#{item.birthDate}" >
                                                        <f:convertDateTime pattern="dd/MM/yyyy" />
                                                                </h:outputText>
                                </h:column>
                                <h:column>
                                        <f:facet name="header">
                                        <h:outputText value="Nº Experiências"/>
                                    </f:facet>
                                        <h:outputText value="#{ fn:length(item.personExperiences) }" />                                                         
                                </h:column>
                                <h:column>
                                        <f:facet name="header">
                                        <h:outputText value="Ativo"/>
                                    </f:facet>
                                    <h:selectBooleanCheckbox value="#{item.active}" >
                                        <f:ajax event="click" listener="#{personController.activeChange(item)}" immediate="true"/>
                                    </h:selectBooleanCheckbox>
                                </h:column>
                                
                                <h:column>
                            <f:facet name="header">
                                <h:outputText escape="false" value="Ação"/>
                            </f:facet>
                            
                            <h:link outcome="/person/detail">
                            			<h:graphicImage value="/images/show.png" />
                                        <f:param name="personId" value="#{item.personId}" />
                            </h:link>
                            <h:outputText value=" "/>
                            
                            <h:link outcome="/person/edit">
                            			<h:graphicImage value="/images/edit.png" />
                                        <f:param name="personId" value="#{item.personId}"/>
                                       
                            </h:link>
                            <h:outputText value=" "/>
                            <h:commandButton value="Excluir" action="#{personController.delete(item)}" image="/images/delete.png" />
                        </h:column>
                            </h:dataTable>
                </h:form>
                    
                </ui:define>
        </ui:composition>
